package com.bestescortbedsystem.controller.bed;

import com.bestescortbedsystem.entity.SesBedMessage;
import com.bestescortbedsystem.entity.SesBedType;
import com.bestescortbedsystem.entity.SesHospitalinfo;
import com.bestescortbedsystem.service.BedService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * ClassName: BedController
 * Package: com.bestescortbedsystem.controller.bed
 *
 * @author: guanzepeng
 * @Date: 2021/2/26 15:11 星期五
 * @Description: 床的controller
 */
@RestController
@RequestMapping("/bed")
@Slf4j
@Api(tags = "床的controller")
public class BedController {

	@Resource
	private BedService bedService;

	/**
	 * 查询床位的订单信息
	 * @param session 传入session
	 * @param pageNum 从第几条数据开始分页
	 * @param pageSize 第几页
	 * @param hospitalinfoId 传入医院ID
	 * @param bedtypeid 传入床位ID
	 * @param hospitalinfoDepartmentid 传入科室ID
	 * @return 返回Map集合
	 */
	@PostMapping("/find")
	@ApiOperation(value = "查询床位订单信息的方法,返回Map集合", response = Map.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value = "从第几条数据开始分页", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pafeSize", value = "第几页", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "hospitalinfoId", value = "医院ID", required = false, dataTypeClass = Long.class),
			@ApiImplicitParam(name = "bedtypeid", value = "床位ID", required = false, dataTypeClass = Long.class),
			@ApiImplicitParam(name = "hospitalinfoDepartmentid", value = "科室ID", required = false, dataTypeClass = Long.class)
	})
	public Map<String, Object> findBedMessage( HttpSession session,
																						@RequestParam(defaultValue = "1") Integer pageNum,
	                                          @RequestParam(defaultValue = "10") Integer pageSize,
	                                          @RequestParam(defaultValue = "0") Long hospitalinfoId,
	                                          @RequestParam(defaultValue = "0") Long bedtypeid,
	                                           @RequestParam(defaultValue = "0") Long hospitalinfoDepartmentid) {
		Map<String, Object> message = bedService.findBedMessage(pageNum, pageSize, hospitalinfoId, bedtypeid, hospitalinfoDepartmentid);
		Object username = session.getAttribute("username");
		if(username == null) {
			message.put("username",null);
		}else {
			message.put("username", session.getAttribute("username"));
		}
		return message;
	}

	/**
	 * 根据租借订单ID删除一条数据
	 * @param bedmessageId 传入租借订单ID
	 * @return 返回Boolean
	 */
	@DeleteMapping("/delete")
	@ApiOperation(value = "根据床位信息ID删除一条床位订单", response = Boolean.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "bedmessageId", value = "传入租借订单ID", required = true, dataTypeClass = Long.class)
	})
	public Boolean deleteBedMessage(Long bedmessageId) {
		if (bedmessageId == null) {
			return false;
		}
		Boolean b = bedService.deleteBedMessage(bedmessageId);
		return b;
	}

	/**
	 * 修改床位开关机状态
	 * @param bedtypeStatus 传入要修改为几号状态,3为关机,0为闲
	 * @param bedtypeId 传入要修改的床位ID
	 * @return 返回对应的状态数字,如果失败返回-1
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改床位开关机状态", response = Integer.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "bedtypeStatus", value = "传入要修改为几号状态,3为关机,0为闲", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "bedtypeId", value = "传入要修改的床位ID", required = true, dataTypeClass = Integer.class)
	})
	public Integer updateOff(Integer bedtypeStatus, Integer bedtypeId) {
		if(bedtypeStatus == null || bedtypeId == null) {
			return -1;
		}
		Integer integer = bedService.updateOff(bedtypeStatus, bedtypeId);
		return integer;
	}

	/**
	 * 根据传入的数据新增一条床位订单
	 * @param sesBedMessage 传入对象
	 * @param sesBedType 传入对象
	 * @return 返回Boolean
	 */
	@PostMapping("/insert")
	@ApiOperation(value = "根据传入的数据新增一条床位订单", response = Boolean.class)
	public Boolean insertBedMessage(SesBedMessage sesBedMessage, SesBedType sesBedType) {
		if(sesBedMessage == null) {
			return false;
		}
		Boolean b = bedService.insertBedMessage(sesBedMessage, sesBedType);
		return b;
	}

	/**
	 * 根据医院ID查询所有的科室
	 * @param hospitalinfoid 传入医院ID
	 * @return 返回SesHospitalinfo
	 */
	@PostMapping("/findbyid")
	@ApiOperation(value = "根据医院ID查询所有的科室", response = SesHospitalinfo.class)
	@ApiImplicitParam(name = "hospitalinfoid", value = "医院ID", required = true, dataTypeClass = Long.class)
	public SesHospitalinfo findById(Long hospitalinfoid) {
		if(hospitalinfoid == null) {
			return new SesHospitalinfo();
		}
		SesHospitalinfo byId = bedService.findById(hospitalinfoid);
		return byId;
	}

}
